/**
 * @author liuchun
 */
public class Shot implements Runnable{


    int x;//子弹x坐标
    int y;//子弹y坐标
    int direct = 0;
    int speed = 3;
    boolean isLive = true;//判断子弹是否还存在

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {//射击行为
        while (true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //根据方向改变x,y坐标
            switch (direct){
                case 0://上
                    y -= speed;
                    break;
                case 1://右
                    x += speed;
                    break;
                case 2://下
                    y += speed;
                    break;
                case 3://左
                    x -= speed;
                    break;
            }
            //System.out.println("子弹 x =" + x +"y =" + y);
            //当子弹触碰边界和敌人坦克时退出
            if (!(x >= 0 && x <= 1000 && y >= 0 && y <= 750 && isLive)) {
                isLive = false;
                break;
            }

        }
    }
}
